Skip to contentSkip to conversation

Change in openvpn[master]: Allowing installing FreeBSD routes with interface instead of next-hop

Openvpn-devel In review plaisthos (Code Review) 2 participants 8 messages Sep 16, 2025 – Oct 6, 2025 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): gerrit.1758030602000.I88e16e15fad065cb310d38f09924053efc3a6ce5@...2715...

#1 lore raw

Attention is currently required from: flichtenheld.

Hello flichtenheld,

I'd like you to do a code review.
Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1193?usp=email

to review the following change.

Change subject: Allowing installing FreeBSD routes with interface instead of next-hop
......................................................................

Allowing installing FreeBSD routes with interface instead of next-hop

This matches the Linux behaviour of the net_route add/delete commands

Change-Id I88e16e15fad065cb310d38f09924053efc3a6ce5

---
M src/openvpn/networking_freebsd.c

1 file changed, 35 insertions(+), 11 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/93/1193/1

src/openvpn/networking_freebsd.c +35 -11
index b47444c..a0e7571 100644
@@ -15,17 +15,29 @@
     char buf1[INET_ADDRSTRLEN], buf2[INET_ADDRSTRLEN];
     in_addr_t _dst, _gw;
     struct argv argv = argv_new();
-    bool status;
+
+    ASSERT(gw || iface);
 
     _dst = ntohl(*dst);
-    _gw = ntohl(*gw);
 
-    argv_printf(&argv, "%s %s -net %s/%d %s -fib %d", ROUTE_PATH, op,
-                inet_ntop(AF_INET, &_dst, buf1, sizeof(buf1)), prefixlen,
-                inet_ntop(AF_INET, &_gw, buf2, sizeof(buf2)), table);
+    /* if gw is 0 (=0.0.0.0), which is not a valid gateway,
+     * we are installing a route with the interface as target instead */
+    if (gw)
+    {
+        _gw = ntohl(*gw);
+        argv_printf(&argv, "%s %s -net %s/%d %s -fib %d", ROUTE_PATH, op,
+                    inet_ntop(AF_INET, &_dst, buf1, sizeof(buf1)), prefixlen,
+                    inet_ntop(AF_INET, &_gw, buf2, sizeof(buf2)), table);
+    }
+    else
+    {
+        argv_printf(&argv, "%s %s -net %s/%d -iface %s -fib %d", ROUTE_PATH, op,
+                    inet_ntop(AF_INET, &_dst, buf1, sizeof(buf1)), prefixlen,
+                    iface, table);
+    }
 
     argv_msg(M_INFO, &argv);
-    status = openvpn_execve_check(&argv, NULL, 0, "ERROR: FreeBSD route command failed");
+    bool status = openvpn_execve_check(&argv, NULL, 0, "ERROR: FreeBSD route command failed");
 
     argv_free(&argv);
 
@@ -38,14 +50,26 @@
 {
     char buf1[INET6_ADDRSTRLEN], buf2[INET6_ADDRSTRLEN];
     struct argv argv = argv_new();
-    bool status;
 
-    argv_printf(&argv, "%s -6 %s -net %s/%d %s -fib %d", ROUTE_PATH, op,
-                inet_ntop(AF_INET6, dst, buf1, sizeof(buf1)), prefixlen,
-                inet_ntop(AF_INET6, gw, buf2, sizeof(buf2)), table);
+    ASSERT(gw || iface);
+    /* if gw is NULL, we are installing a route with the interface as target
+     * instead */
+    if (gw)
+    {
+        argv_printf(&argv, "%s -6 %s -net %s/%d %s -fib %d", ROUTE_PATH, op,
+                    inet_ntop(AF_INET6, dst, buf1, sizeof(buf1)), prefixlen,
+                    inet_ntop(AF_INET6, gw, buf2, sizeof(buf2)), table);
+    }
+    else
+    {
+        argv_printf(&argv, "%s -6 %s -net %s/%d -iface %s -fib %d", ROUTE_PATH, op,
+                    inet_ntop(AF_INET6, dst, buf1, sizeof(buf1)), prefixlen,
+                    iface, table);
+    }
+
 
     argv_msg(M_INFO, &argv);
-    status = openvpn_execve_check(&argv, NULL, 0, "ERROR: FreeBSD route command failed");
+    bool status = openvpn_execve_check(&argv, NULL, 0, "ERROR: FreeBSD route command failed");
 
     argv_free(&argv);
 

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1193?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I88e16e15fad065cb310d38f09924053efc3a6ce5
Gerrit-Change-Number: 1193
Gerrit-PatchSet: 1
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newchange

#2 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/1193?usp=email )

Change subject: Allowing installing FreeBSD routes with interface instead of next-hop
......................................................................

Patch Set 3: Code-Review-1

(1 comment)

File src/openvpn/networking_freebsd.c:

http://gerrit.openvpn.net/c/openvpn/+/1193/comment/ca46df8e_422ac899 :
PS3, Line 23: /* if gw is 0 (=0.0.0.0), which is not a valid gateway,
are you passing in NULL or "a pointer to 0.0.0.0"? The code says "NULL" and the comment says "gw is 0.0.0.0" which would technically be "a pointer to 0.0.0.0"...

Maybe just word it the same as in IPv6... if we have no gateway (gw is NULL), we are installing a route with the interface as target instead or so.

But the logic is still confusing, the comment says "if we have no gateway" and the condition does "if(gateway)" and the "interface route" is down in the else branch...

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1193?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I88e16e15fad065cb310d38f09924053efc3a6ce5
Gerrit-Change-Number: 1193
Gerrit-PatchSet: 3
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Sat, 27 Sep 2025 20:27:42 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

#3 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/1193?usp=email )

Change subject: Allowing installing FreeBSD routes with interface instead of next-hop
......................................................................

Patch Set 3:

(1 comment)

File src/openvpn/networking_freebsd.c:

http://gerrit.openvpn.net/c/openvpn/+/1193/comment/5c8a40a2_8ceda728 :
PS3, Line 23: /* if gw is 0 (=0.0.0.0), which is not a valid gateway,

Quoted 1 line

are you passing in NULL or "a pointer to 0.0.0. […]

```
/* if we have a gateway (GW != NULL) install route to gateway IP
 * if not, install "connected" route to interface (required for ifconfig-push IPs)
 */
```

something like this? I think this would help understanding the code and be in line with the if(gw)...

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1193?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I88e16e15fad065cb310d38f09924053efc3a6ce5
Gerrit-Change-Number: 1193
Gerrit-PatchSet: 3
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Sun, 28 Sep 2025 11:24:04 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: cron2 <[email protected]...>
Gerrit-MessageType: comment

#4 lore raw
In reply to a message not in the archive

Attention is currently required from: cron2, flichtenheld, plaisthos.

Hello cron2, flichtenheld,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1193?usp=email

to look at the new patch set (#4).

The following approvals got outdated and were removed:
Code-Review-1 by cron2

Change subject: Allowing installing FreeBSD routes with interface instead of next-hop
......................................................................

Allowing installing FreeBSD routes with interface instead of next-hop

This matches the Linux behaviour of the net_route add/delete commands

Change-Id I88e16e15fad065cb310d38f09924053efc3a6ce5

---
M src/openvpn/networking_freebsd.c

1 file changed, 35 insertions(+), 11 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/93/1193/4

src/openvpn/networking_freebsd.c +35 -11
index b47444c..b020f51 100644
@@ -15,17 +15,29 @@
     char buf1[INET_ADDRSTRLEN], buf2[INET_ADDRSTRLEN];
     in_addr_t _dst, _gw;
     struct argv argv = argv_new();
-    bool status;
+
+    ASSERT(gw || iface);
 
     _dst = ntohl(*dst);
-    _gw = ntohl(*gw);
 
-    argv_printf(&argv, "%s %s -net %s/%d %s -fib %d", ROUTE_PATH, op,
-                inet_ntop(AF_INET, &_dst, buf1, sizeof(buf1)), prefixlen,
-                inet_ntop(AF_INET, &_gw, buf2, sizeof(buf2)), table);
+    /* if gw is NULL we are installing a route with the interface as
+     * target instead */
+    if (gw)
+    {
+        _gw = ntohl(*gw);
+        argv_printf(&argv, "%s %s -net %s/%d %s -fib %d", ROUTE_PATH, op,
+                    inet_ntop(AF_INET, &_dst, buf1, sizeof(buf1)), prefixlen,
+                    inet_ntop(AF_INET, &_gw, buf2, sizeof(buf2)), table);
+    }
+    else
+    {
+        argv_printf(&argv, "%s %s -net %s/%d -iface %s -fib %d", ROUTE_PATH, op,
+                    inet_ntop(AF_INET, &_dst, buf1, sizeof(buf1)), prefixlen,
+                    iface, table);
+    }
 
     argv_msg(M_INFO, &argv);
-    status = openvpn_execve_check(&argv, NULL, 0, "ERROR: FreeBSD route command failed");
+    bool status = openvpn_execve_check(&argv, NULL, 0, "ERROR: FreeBSD route command failed");
 
     argv_free(&argv);
 
@@ -38,14 +50,26 @@
 {
     char buf1[INET6_ADDRSTRLEN], buf2[INET6_ADDRSTRLEN];
     struct argv argv = argv_new();
-    bool status;
 
-    argv_printf(&argv, "%s -6 %s -net %s/%d %s -fib %d", ROUTE_PATH, op,
-                inet_ntop(AF_INET6, dst, buf1, sizeof(buf1)), prefixlen,
-                inet_ntop(AF_INET6, gw, buf2, sizeof(buf2)), table);
+    ASSERT(gw || iface);
+    /* if gw is NULL, we are installing a route with the interface as target
+     * instead */
+    if (gw)
+    {
+        argv_printf(&argv, "%s -6 %s -net %s/%d %s -fib %d", ROUTE_PATH, op,
+                    inet_ntop(AF_INET6, dst, buf1, sizeof(buf1)), prefixlen,
+                    inet_ntop(AF_INET6, gw, buf2, sizeof(buf2)), table);
+    }
+    else
+    {
+        argv_printf(&argv, "%s -6 %s -net %s/%d -iface %s -fib %d", ROUTE_PATH, op,
+                    inet_ntop(AF_INET6, dst, buf1, sizeof(buf1)), prefixlen,
+                    iface, table);
+    }
+
 
     argv_msg(M_INFO, &argv);
-    status = openvpn_execve_check(&argv, NULL, 0, "ERROR: FreeBSD route command failed");
+    bool status = openvpn_execve_check(&argv, NULL, 0, "ERROR: FreeBSD route command failed");
 
     argv_free(&argv);
 

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1193?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I88e16e15fad065cb310d38f09924053efc3a6ce5
Gerrit-Change-Number: 1193
Gerrit-PatchSet: 4
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>

#5 lore raw

PATCH v4 1/1 Allowing installing FreeBSD routes with interface instead of next-hop

In reply to a message not in the archive

From: Arne Schwabe <[email protected]...>

This matches the Linux behaviour of the net_route add/delete commands

Change-Id I88e16e15fad065cb310d38f09924053efc3a6ce5

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1193
---

This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1193
This mail reflects revision 4 of this Change.

Acked-by according to Gerrit (reflected above):

src/openvpn/networking_freebsd.c +35 -11
index b47444c..b020f51 100644
@@ -15,17 +15,29 @@
     char buf1[INET_ADDRSTRLEN], buf2[INET_ADDRSTRLEN];
     in_addr_t _dst, _gw;
     struct argv argv = argv_new();
-    bool status;
+
+    ASSERT(gw || iface);
 
     _dst = ntohl(*dst);
-    _gw = ntohl(*gw);
 
-    argv_printf(&argv, "%s %s -net %s/%d %s -fib %d", ROUTE_PATH, op,
-                inet_ntop(AF_INET, &_dst, buf1, sizeof(buf1)), prefixlen,
-                inet_ntop(AF_INET, &_gw, buf2, sizeof(buf2)), table);
+    /* if gw is NULL we are installing a route with the interface as
+     * target instead */
+    if (gw)
+    {
+        _gw = ntohl(*gw);
+        argv_printf(&argv, "%s %s -net %s/%d %s -fib %d", ROUTE_PATH, op,
+                    inet_ntop(AF_INET, &_dst, buf1, sizeof(buf1)), prefixlen,
+                    inet_ntop(AF_INET, &_gw, buf2, sizeof(buf2)), table);
+    }
+    else
+    {
+        argv_printf(&argv, "%s %s -net %s/%d -iface %s -fib %d", ROUTE_PATH, op,
+                    inet_ntop(AF_INET, &_dst, buf1, sizeof(buf1)), prefixlen,
+                    iface, table);
+    }
 
     argv_msg(M_INFO, &argv);
-    status = openvpn_execve_check(&argv, NULL, 0, "ERROR: FreeBSD route command failed");
+    bool status = openvpn_execve_check(&argv, NULL, 0, "ERROR: FreeBSD route command failed");
 
     argv_free(&argv);
 
@@ -38,14 +50,26 @@
 {
     char buf1[INET6_ADDRSTRLEN], buf2[INET6_ADDRSTRLEN];
     struct argv argv = argv_new();
-    bool status;
 
-    argv_printf(&argv, "%s -6 %s -net %s/%d %s -fib %d", ROUTE_PATH, op,
-                inet_ntop(AF_INET6, dst, buf1, sizeof(buf1)), prefixlen,
-                inet_ntop(AF_INET6, gw, buf2, sizeof(buf2)), table);
+    ASSERT(gw || iface);
+    /* if gw is NULL, we are installing a route with the interface as target
+     * instead */
+    if (gw)
+    {
+        argv_printf(&argv, "%s -6 %s -net %s/%d %s -fib %d", ROUTE_PATH, op,
+                    inet_ntop(AF_INET6, dst, buf1, sizeof(buf1)), prefixlen,
+                    inet_ntop(AF_INET6, gw, buf2, sizeof(buf2)), table);
+    }
+    else
+    {
+        argv_printf(&argv, "%s -6 %s -net %s/%d -iface %s -fib %d", ROUTE_PATH, op,
+                    inet_ntop(AF_INET6, dst, buf1, sizeof(buf1)), prefixlen,
+                    iface, table);
+    }
+
 
     argv_msg(M_INFO, &argv);
-    status = openvpn_execve_check(&argv, NULL, 0, "ERROR: FreeBSD route command failed");
+    bool status = openvpn_execve_check(&argv, NULL, 0, "ERROR: FreeBSD route command failed");
 
     argv_free(&argv);
 
#6 lore raw

[Openvpn-devel] [PATCH applied] Re: Allowing installing FreeBSD routes with interface instead of next-hop

There is not much to test here, as the "new code" is only used for a case not yet supported by the rest of the code (--ifconfig-push IPs outside --server subnet, with DCO, on FreeBSD). Patch for that is in gerrit #1192, but that needs more testing.

The code in question is currently only excercised at all for --iroute on FreeBSD DCO -> tested there, works.

At a future point in time (after 2.7.0 release) I think I/we should remove the TARGET_FREEBSD parts from route.c, and use networking_freebsd.c instead (adding what is missing, namely "fe80::1%em0" gateways with embedded NIC).

As discussed in IRC, I have amended the comment a bit, and then a bit more, to make it easier to understand what is happening and when it's needed. No actual code change.

Your patch has been applied to the master branch.

commit cbcfb9ab3ea90e1d09e5783bdb3bbd18ac0328d1

Author: Arne Schwabe
Date:   Mon Oct 6 16:58:37 2025 +0200
     Allowing installing FreeBSD routes with interface instead of next-hop

     Signed-off-by: Arne Schwabe <[email protected]...>
     Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1193
     Message-Id: <[email protected]...>
     URL: https://sourceforge.net/p/openvpn/mailman/message/59242876/
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#7 lore raw
In reply to a message not in the archive

cron2 has uploaded a new patch set (#5) to the change originally created by plaisthos. ( http://gerrit.openvpn.net/c/openvpn/+/1193?usp=email )

Change subject: Allowing installing FreeBSD routes with interface instead of next-hop
......................................................................

Allowing installing FreeBSD routes with interface instead of next-hop

This matches the Linux behaviour of the net_route add/delete commands

Change-Id I88e16e15fad065cb310d38f09924053efc3a6ce5

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1193
Message-Id: <[email protected]...>
URL: https://sourceforge.net/p/openvpn/mailman/message/59242876/

---
M src/openvpn/networking_freebsd.c

1 file changed, 40 insertions(+), 11 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/93/1193/5

src/openvpn/networking_freebsd.c +40 -11
index b47444c..04051a6 100644
@@ -15,17 +15,31 @@
     char buf1[INET_ADDRSTRLEN], buf2[INET_ADDRSTRLEN];
     in_addr_t _dst, _gw;
     struct argv argv = argv_new();
-    bool status;
+
+    ASSERT(gw || iface);
 
     _dst = ntohl(*dst);
-    _gw = ntohl(*gw);
 
-    argv_printf(&argv, "%s %s -net %s/%d %s -fib %d", ROUTE_PATH, op,
-                inet_ntop(AF_INET, &_dst, buf1, sizeof(buf1)), prefixlen,
-                inet_ntop(AF_INET, &_gw, buf2, sizeof(buf2)), table);
+    /* if we have a gateway (GW != NULL) install route to gateway IP
+     * if not, install "connected" route to interface
+     * (needed to make 'ifconfig-push IPs outside server subnet' work)
+     */
+    if (gw)
+    {
+        _gw = ntohl(*gw);
+        argv_printf(&argv, "%s %s -net %s/%d %s -fib %d", ROUTE_PATH, op,
+                    inet_ntop(AF_INET, &_dst, buf1, sizeof(buf1)), prefixlen,
+                    inet_ntop(AF_INET, &_gw, buf2, sizeof(buf2)), table);
+    }
+    else
+    {
+        argv_printf(&argv, "%s %s -net %s/%d -iface %s -fib %d", ROUTE_PATH, op,
+                    inet_ntop(AF_INET, &_dst, buf1, sizeof(buf1)), prefixlen,
+                    iface, table);
+    }
 
     argv_msg(M_INFO, &argv);
-    status = openvpn_execve_check(&argv, NULL, 0, "ERROR: FreeBSD route command failed");
+    bool status = openvpn_execve_check(&argv, NULL, 0, "ERROR: FreeBSD route command failed");
 
     argv_free(&argv);
 
@@ -38,14 +52,29 @@
 {
     char buf1[INET6_ADDRSTRLEN], buf2[INET6_ADDRSTRLEN];
     struct argv argv = argv_new();
-    bool status;
 
-    argv_printf(&argv, "%s -6 %s -net %s/%d %s -fib %d", ROUTE_PATH, op,
-                inet_ntop(AF_INET6, dst, buf1, sizeof(buf1)), prefixlen,
-                inet_ntop(AF_INET6, gw, buf2, sizeof(buf2)), table);
+    ASSERT(gw || iface);
+
+    /* if we have a gateway (GW != NULL) install route to gateway IP
+     * if not, install "connected" route to interface
+     * (needed to make 'ifconfig-push IPs outside server subnet' work)
+     */
+    if (gw)
+    {
+        argv_printf(&argv, "%s -6 %s -net %s/%d %s -fib %d", ROUTE_PATH, op,
+                    inet_ntop(AF_INET6, dst, buf1, sizeof(buf1)), prefixlen,
+                    inet_ntop(AF_INET6, gw, buf2, sizeof(buf2)), table);
+    }
+    else
+    {
+        argv_printf(&argv, "%s -6 %s -net %s/%d -iface %s -fib %d", ROUTE_PATH, op,
+                    inet_ntop(AF_INET6, dst, buf1, sizeof(buf1)), prefixlen,
+                    iface, table);
+    }
+
 
     argv_msg(M_INFO, &argv);
-    status = openvpn_execve_check(&argv, NULL, 0, "ERROR: FreeBSD route command failed");
+    bool status = openvpn_execve_check(&argv, NULL, 0, "ERROR: FreeBSD route command failed");
 
     argv_free(&argv);
 

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1193?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I88e16e15fad065cb310d38f09924053efc3a6ce5
Gerrit-Change-Number: 1193
Gerrit-PatchSet: 5
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>

#8 lore raw
In reply to a message not in the archive

cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/1193?usp=email )

Change subject: Allowing installing FreeBSD routes with interface instead of next-hop
......................................................................

Allowing installing FreeBSD routes with interface instead of next-hop

This matches the Linux behaviour of the net_route add/delete commands

Change-Id I88e16e15fad065cb310d38f09924053efc3a6ce5

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1193
Message-Id: <[email protected]...>
URL: https://sourceforge.net/p/openvpn/mailman/message/59242876/

---
M src/openvpn/networking_freebsd.c

1 file changed, 40 insertions(+), 11 deletions(-)
src/openvpn/networking_freebsd.c +40 -11
index b47444c..04051a6 100644
@@ -15,17 +15,31 @@
     char buf1[INET_ADDRSTRLEN], buf2[INET_ADDRSTRLEN];
     in_addr_t _dst, _gw;
     struct argv argv = argv_new();
-    bool status;
+
+    ASSERT(gw || iface);
 
     _dst = ntohl(*dst);
-    _gw = ntohl(*gw);
 
-    argv_printf(&argv, "%s %s -net %s/%d %s -fib %d", ROUTE_PATH, op,
-                inet_ntop(AF_INET, &_dst, buf1, sizeof(buf1)), prefixlen,
-                inet_ntop(AF_INET, &_gw, buf2, sizeof(buf2)), table);
+    /* if we have a gateway (GW != NULL) install route to gateway IP
+     * if not, install "connected" route to interface
+     * (needed to make 'ifconfig-push IPs outside server subnet' work)
+     */
+    if (gw)
+    {
+        _gw = ntohl(*gw);
+        argv_printf(&argv, "%s %s -net %s/%d %s -fib %d", ROUTE_PATH, op,
+                    inet_ntop(AF_INET, &_dst, buf1, sizeof(buf1)), prefixlen,
+                    inet_ntop(AF_INET, &_gw, buf2, sizeof(buf2)), table);
+    }
+    else
+    {
+        argv_printf(&argv, "%s %s -net %s/%d -iface %s -fib %d", ROUTE_PATH, op,
+                    inet_ntop(AF_INET, &_dst, buf1, sizeof(buf1)), prefixlen,
+                    iface, table);
+    }
 
     argv_msg(M_INFO, &argv);
-    status = openvpn_execve_check(&argv, NULL, 0, "ERROR: FreeBSD route command failed");
+    bool status = openvpn_execve_check(&argv, NULL, 0, "ERROR: FreeBSD route command failed");
 
     argv_free(&argv);
 
@@ -38,14 +52,29 @@
 {
     char buf1[INET6_ADDRSTRLEN], buf2[INET6_ADDRSTRLEN];
     struct argv argv = argv_new();
-    bool status;
 
-    argv_printf(&argv, "%s -6 %s -net %s/%d %s -fib %d", ROUTE_PATH, op,
-                inet_ntop(AF_INET6, dst, buf1, sizeof(buf1)), prefixlen,
-                inet_ntop(AF_INET6, gw, buf2, sizeof(buf2)), table);
+    ASSERT(gw || iface);
+
+    /* if we have a gateway (GW != NULL) install route to gateway IP
+     * if not, install "connected" route to interface
+     * (needed to make 'ifconfig-push IPs outside server subnet' work)
+     */
+    if (gw)
+    {
+        argv_printf(&argv, "%s -6 %s -net %s/%d %s -fib %d", ROUTE_PATH, op,
+                    inet_ntop(AF_INET6, dst, buf1, sizeof(buf1)), prefixlen,
+                    inet_ntop(AF_INET6, gw, buf2, sizeof(buf2)), table);
+    }
+    else
+    {
+        argv_printf(&argv, "%s -6 %s -net %s/%d -iface %s -fib %d", ROUTE_PATH, op,
+                    inet_ntop(AF_INET6, dst, buf1, sizeof(buf1)), prefixlen,
+                    iface, table);
+    }
+
 
     argv_msg(M_INFO, &argv);
-    status = openvpn_execve_check(&argv, NULL, 0, "ERROR: FreeBSD route command failed");
+    bool status = openvpn_execve_check(&argv, NULL, 0, "ERROR: FreeBSD route command failed");
 
     argv_free(&argv);
 

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1193?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I88e16e15fad065cb310d38f09924053efc3a6ce5
Gerrit-Change-Number: 1193
Gerrit-PatchSet: 5
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>